<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>基础知识</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link href="https://cdn.bootcdn.net/ajax/libs/animate.css/3.2.3/animate.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../static/css/public.css" />
</head>
<body>
	<!-- 回到顶部 -->
	<div class="topBtn">
		<a href="#top">
			<i class="fa fa-long-arrow-up"></i>
		</a>
	</div>
	<!--右边内容-->
	<div id="app" class="main animated fadeInRight">
		<div class="shadow">
			<div class="Table">
				<div class="TableRow" v-for="(el,index) in list" v-cloak>
					<a class="RowLeft" :href="'#'+el.id">{{el.name}}</a>
					<span class="RowRight">{{el.explain}}</span>
				</div>
			</div>
			<div>
				<h4 id="assign">Object.assign</h4>
				<div>定义:将源对象（source）的所有可枚举属性，复制到目标对象（target）</div>
				<pre>
	合并多个对象
	var target = { a: 1, b: 1 };
	var source1 = { b: 2, c: 2 };
	var source2 = { c: 3 };
	Object.assign(target, source1, source2);
				</pre>
				<div class="red">这个是伪深度拷贝,只能拷贝第一层</div>
			</div>
			<div>
				<h4 id="stringify">JSON.stringify</h4>
				<p>原理:是将对象转化为字符串,而字符串是简单数据类型</p>
				<pre>
	let object=JSON.parse(JSON.stringify(obj))
				</pre>
			</div>
			<div>
				<h4 id="recursion">递归拷贝</h4>
				<pre>
		function deepClone(source){
		  const targetObj = source.constructor === Array ? [] : {}; // 判断复制的目标是数组还是对象
		  for(let keys in source){ // 遍历目标
		    if(source.hasOwnProperty(keys)){
		      if(source[keys] && typeof source[keys] === 'object'){ // 如果值是对象，就递归一下
		        targetObj[keys] = source[keys].constructor === Array ? [] : {};
		        targetObj[keys] = deepClone(source[keys]);
		      }else{ // 如果不是，就直接赋值
		        targetObj[keys] = source[keys];
		      }
		    }
		  }
		  return targetObj;
		}  
				</pre>
			</div>
			
		</div>
	</div>
	<!--页面加载进度条-->
	<script src="https://cdn.bootcdn.net/ajax/libs/pace/0.5.0/pace.min.js"></script>
	<!--定义数据-->
	<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.5.17/vue.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var app = new Vue({
			el: "#app",
			data: function () {
				return {
					list:[
						{name:"Object.assign",id:"assign",explain:'只是浅拷贝，和slice方法一样，'},
						{name:"JSON.stringify",id:"stringify",explain:'无法拷贝函数对象'},
						{name:"递归",id:"recursion",explain:'无法拷贝函数对象'},
					]
				}
			},
		})
	</script>
</body>

</html>